VERSION 5.00
Begin VB.Form customer 
   Caption         =   "User Management"
   ClientHeight    =   9675
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   12960
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   9675
   ScaleWidth      =   12960
   WindowState     =   2  'Maximized
   Begin VB.CommandButton Command3 
      Caption         =   "Next"
      Height          =   495
      Left            =   5400
      TabIndex        =   93
      ToolTipText     =   "please input short id or id!"
      Top             =   9240
      Width           =   1440
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Previous"
      Height          =   495
      Left            =   3960
      TabIndex        =   92
      ToolTipText     =   "please input short id or id!"
      Top             =   9240
      Width           =   1440
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Operation History"
      Height          =   495
      Left            =   240
      TabIndex        =   91
      ToolTipText     =   "Have not done yet!"
      Top             =   9240
      Width           =   3720
   End
   Begin VB.CommandButton cmdLook 
      Caption         =   "Have a look at this customer"
      Height          =   495
      Left            =   6840
      TabIndex        =   90
      ToolTipText     =   "Have not done yet!"
      Top             =   9240
      Width           =   4200
   End
   Begin VB.Frame frmSort 
      Caption         =   " Classification"
      Height          =   5415
      Left            =   12120
      TabIndex        =   80
      Top             =   3720
      Width           =   7455
      Begin VB.CommandButton cmdAddClass 
         Caption         =   "Add more sub classifications"
         Height          =   375
         Left            =   240
         TabIndex        =   87
         Top             =   4920
         Width           =   7095
      End
      Begin VB.CommandButton cmdRight1 
         Caption         =   "<--"
         Height          =   375
         Index           =   2
         Left            =   4680
         TabIndex        =   86
         Top             =   2640
         Width           =   495
      End
      Begin VB.CommandButton cmdRight1 
         Caption         =   "-->"
         Height          =   375
         Index           =   1
         Left            =   4680
         TabIndex        =   85
         Top             =   1440
         Width           =   495
      End
      Begin VB.CommandButton cmdRight1 
         Caption         =   "-->"
         Height          =   375
         Index           =   0
         Left            =   1920
         TabIndex        =   84
         Top             =   1440
         Width           =   495
      End
      Begin VB.ListBox List1 
         Height          =   4350
         Index           =   2
         Left            =   5280
         TabIndex        =   83
         Top             =   360
         Width           =   2055
      End
      Begin VB.ListBox List1 
         Height          =   4350
         Index           =   1
         Left            =   2520
         TabIndex        =   82
         Top             =   360
         Width           =   2055
      End
      Begin VB.ListBox List1 
         Height          =   4350
         Index           =   0
         Left            =   240
         TabIndex        =   81
         Top             =   360
         Width           =   1575
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Trading Hours"
      Height          =   3135
      Left            =   12120
      TabIndex        =   57
      Top             =   360
      Width           =   7455
      Begin VB.TextBox txtTime 
         Appearance      =   0  'Flat
         Height          =   855
         Left            =   240
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   89
         Top             =   2160
         Width           =   6975
      End
      Begin VB.CheckBox ckHrs 
         Caption         =   "Use the following text only"
         Height          =   255
         Left            =   240
         TabIndex        =   88
         Top             =   1920
         Width           =   3255
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   13
         Left            =   4440
         TabIndex        =   79
         Top             =   1200
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   12
         Left            =   4440
         TabIndex        =   78
         Top             =   720
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   11
         Left            =   3720
         TabIndex        =   77
         Top             =   1200
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   10
         Left            =   3720
         TabIndex        =   76
         Top             =   720
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   9
         Left            =   3000
         TabIndex        =   75
         Top             =   1200
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   8
         Left            =   3000
         TabIndex        =   74
         Top             =   720
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   7
         Left            =   2280
         TabIndex        =   73
         Top             =   1200
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   6
         Left            =   2280
         TabIndex        =   72
         Top             =   720
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   5
         Left            =   1560
         TabIndex        =   71
         Top             =   1200
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   4
         Left            =   1560
         TabIndex        =   70
         Top             =   720
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   3
         Left            =   840
         TabIndex        =   68
         Top             =   1200
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   2
         Left            =   840
         TabIndex        =   67
         Top             =   720
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   1
         Left            =   120
         TabIndex        =   66
         Top             =   1200
         Width           =   735
      End
      Begin VB.TextBox tTime 
         Appearance      =   0  'Flat
         Height          =   285
         Index           =   0
         Left            =   120
         TabIndex        =   65
         Top             =   720
         Width           =   735
      End
      Begin VB.Label Label9 
         Caption         =   "For example: Mon 09:00 - 17:00"
         Height          =   495
         Left            =   240
         TabIndex        =   69
         Top             =   1560
         Width           =   4695
      End
      Begin VB.Label Label8 
         Caption         =   "Sun"
         Height          =   255
         Left            =   4680
         TabIndex        =   64
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label7 
         Caption         =   "Sat"
         Height          =   255
         Left            =   3960
         TabIndex        =   63
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label6 
         Caption         =   "Fri"
         Height          =   255
         Left            =   3240
         TabIndex        =   62
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label5 
         Caption         =   "Thu"
         Height          =   255
         Left            =   2520
         TabIndex        =   61
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label4 
         Caption         =   "Wed"
         Height          =   255
         Left            =   1680
         TabIndex        =   60
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label3 
         Caption         =   "Tue"
         Height          =   255
         Left            =   960
         TabIndex        =   59
         Top             =   360
         Width           =   735
      End
      Begin VB.Label Label2 
         Caption         =   "Mon"
         Height          =   255
         Left            =   240
         TabIndex        =   58
         Top             =   360
         Width           =   735
      End
   End
   Begin VB.CommandButton cmdNew 
      Caption         =   "New Record"
      Height          =   495
      Left            =   2640
      TabIndex        =   56
      ToolTipText     =   "Create a brand new record"
      Top             =   8760
      Width           =   1200
   End
   Begin VB.CommandButton cmdLook4 
      Caption         =   "Seach"
      Height          =   495
      Left            =   3960
      TabIndex        =   53
      ToolTipText     =   "please input short id or id!"
      Top             =   8760
      Width           =   1320
   End
   Begin VB.CommandButton cmdRefresh 
      Caption         =   "Refresh Record"
      Height          =   495
      Left            =   6840
      TabIndex        =   52
      Top             =   8760
      Width           =   1320
   End
   Begin VB.CommandButton cmdBlock 
      Caption         =   "Block "
      Height          =   495
      Left            =   9720
      TabIndex        =   49
      Top             =   8760
      Width           =   1320
   End
   Begin VB.CommandButton cmdUpdate 
      Caption         =   "Update Record"
      Height          =   495
      Left            =   8280
      TabIndex        =   48
      Top             =   8760
      Width           =   1320
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "Delete Record"
      Height          =   495
      Left            =   5400
      TabIndex        =   47
      Top             =   8760
      Width           =   1320
   End
   Begin VB.CommandButton cmdNext 
      Caption         =   "Next Record"
      Height          =   495
      Left            =   1320
      TabIndex        =   46
      ToolTipText     =   "In customer service mode, it will jump to next record accordingly!"
      Top             =   8760
      Width           =   1200
   End
   Begin VB.CommandButton cmdSettings 
      Caption         =   "Settings"
      Height          =   495
      Left            =   240
      TabIndex        =   45
      ToolTipText     =   "Have not done yet!"
      Top             =   8760
      Width           =   1080
   End
   Begin VB.Frame Frame1 
      Caption         =   "Basic Infomation"
      Height          =   8415
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   10815
      Begin VB.ComboBox cmbClassification 
         Height          =   315
         ItemData        =   "Form1.frx":030A
         Left            =   7440
         List            =   "Form1.frx":030C
         Style           =   2  'Dropdown List
         TabIndex        =   55
         Top             =   6360
         Width           =   1815
      End
      Begin VB.ComboBox cmbCity 
         Height          =   315
         Left            =   7440
         Style           =   2  'Dropdown List
         TabIndex        =   54
         Top             =   6840
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   3
         Left            =   1200
         TabIndex        =   50
         Top             =   2760
         Width           =   3495
      End
      Begin VB.CheckBox Check1 
         Caption         =   "Check1"
         Height          =   255
         Index           =   2
         Left            =   7440
         TabIndex        =   44
         Top             =   2640
         Width           =   255
      End
      Begin VB.CheckBox Check1 
         Caption         =   "Check1"
         Height          =   255
         Index           =   1
         Left            =   2760
         TabIndex        =   43
         Top             =   3240
         Width           =   255
      End
      Begin VB.CheckBox Check1 
         Caption         =   "Check1"
         Height          =   255
         Index           =   0
         Left            =   1320
         TabIndex        =   41
         Top             =   3240
         Width           =   255
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Enabled         =   0   'False
         Height          =   375
         Index           =   22
         Left            =   7440
         TabIndex        =   40
         Top             =   7440
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   19
         Left            =   1200
         TabIndex        =   36
         Top             =   7680
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   18
         Left            =   1200
         TabIndex        =   34
         Top             =   7200
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   495
         Index           =   17
         Left            =   7440
         MultiLine       =   -1  'True
         TabIndex        =   32
         Top             =   5640
         Width           =   2895
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   615
         Index           =   16
         Left            =   7440
         MultiLine       =   -1  'True
         TabIndex        =   30
         Top             =   4920
         Width           =   2895
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   615
         Index           =   15
         Left            =   7440
         MultiLine       =   -1  'True
         TabIndex        =   28
         Top             =   4200
         Width           =   2895
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Enabled         =   0   'False
         Height          =   375
         Index           =   14
         Left            =   7440
         TabIndex        =   26
         Top             =   3720
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   615
         Index           =   13
         Left            =   7440
         MultiLine       =   -1  'True
         TabIndex        =   24
         Top             =   3000
         Width           =   2895
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   11
         Left            =   7440
         TabIndex        =   21
         Top             =   1920
         Width           =   2415
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   10
         Left            =   7440
         TabIndex        =   19
         Top             =   1320
         Width           =   2415
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   9
         Left            =   7440
         TabIndex        =   17
         Top             =   600
         Width           =   2415
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   8
         Left            =   1200
         TabIndex        =   15
         Top             =   6720
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   1695
         Index           =   7
         Left            =   1200
         MultiLine       =   -1  'True
         TabIndex        =   13
         Top             =   4920
         Width           =   4335
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   735
         Index           =   6
         Left            =   1200
         MultiLine       =   -1  'True
         TabIndex        =   11
         Top             =   4080
         Width           =   4335
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Enabled         =   0   'False
         Height          =   375
         Index           =   4
         Left            =   1200
         TabIndex        =   9
         Top             =   3600
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   375
         Index           =   2
         Left            =   1200
         TabIndex        =   6
         Top             =   2160
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Height          =   735
         Index           =   1
         Left            =   1200
         MultiLine       =   -1  'True
         TabIndex        =   4
         Top             =   1200
         Width           =   3495
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         Enabled         =   0   'False
         Height          =   375
         Index           =   0
         Left            =   1200
         TabIndex        =   2
         Top             =   600
         Width           =   2295
      End
      Begin VB.Label lblUsrStatus 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   13.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   615
         Left            =   3840
         TabIndex        =   94
         Top             =   240
         Width           =   2295
      End
      Begin VB.Label Label1 
         Caption         =   "Web:"
         Height          =   255
         Index           =   23
         Left            =   360
         TabIndex        =   51
         Top             =   2880
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Recorder:"
         Height          =   495
         Index           =   5
         Left            =   1800
         TabIndex        =   42
         Top             =   3240
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Last login:"
         Height          =   495
         Index           =   22
         Left            =   6360
         TabIndex        =   39
         Top             =   7560
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "City:"
         Height          =   495
         Index           =   21
         Left            =   6600
         TabIndex        =   38
         Top             =   6840
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Classification:"
         Height          =   495
         Index           =   20
         Left            =   6240
         TabIndex        =   37
         Top             =   6360
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "Read Lv:"
         Height          =   495
         Index           =   19
         Left            =   360
         TabIndex        =   35
         Top             =   7800
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Class:"
         Height          =   495
         Index           =   18
         Left            =   480
         TabIndex        =   33
         Top             =   7320
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Event List:"
         Height          =   495
         Index           =   17
         Left            =   6480
         TabIndex        =   31
         Top             =   5760
         Width           =   855
      End
      Begin VB.Label Label1 
         Caption         =   "WhiteList:"
         Height          =   495
         Index           =   16
         Left            =   6480
         TabIndex        =   29
         Top             =   5040
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Blacklist:"
         Height          =   495
         Index           =   15
         Left            =   6480
         TabIndex        =   27
         Top             =   4320
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Register Date:"
         Height          =   495
         Index           =   14
         Left            =   6000
         TabIndex        =   25
         Top             =   3840
         Width           =   1335
      End
      Begin VB.Label Label1 
         Caption         =   "Trading Name:"
         Height          =   495
         Index           =   13
         Left            =   6000
         TabIndex        =   23
         Top             =   3120
         Width           =   1335
      End
      Begin VB.Label Label1 
         Caption         =   "Online:"
         Height          =   495
         Index           =   12
         Left            =   6600
         TabIndex        =   22
         Top             =   2640
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "IM:"
         Height          =   495
         Index           =   11
         Left            =   6600
         TabIndex        =   20
         Top             =   2040
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Phone:"
         Height          =   495
         Index           =   10
         Left            =   6600
         TabIndex        =   18
         Top             =   1440
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Email:"
         Height          =   495
         Index           =   9
         Left            =   6600
         TabIndex        =   16
         Top             =   720
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Photo:"
         Height          =   495
         Index           =   8
         Left            =   480
         TabIndex        =   14
         Top             =   6840
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Intro:"
         Height          =   495
         Index           =   7
         Left            =   360
         TabIndex        =   12
         Top             =   5520
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Slang:"
         Height          =   495
         Index           =   6
         Left            =   360
         TabIndex        =   10
         Top             =   4200
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Found Date"
         Height          =   615
         Index           =   4
         Left            =   240
         TabIndex        =   8
         Top             =   3600
         Width           =   855
      End
      Begin VB.Label Label1 
         Caption         =   "ThirdPart:"
         Height          =   495
         Index           =   3
         Left            =   360
         TabIndex        =   7
         Top             =   3240
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Fax:"
         Height          =   495
         Index           =   2
         Left            =   360
         TabIndex        =   5
         Top             =   2280
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Addr:"
         Height          =   495
         Index           =   1
         Left            =   360
         TabIndex        =   3
         Top             =   1320
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "ID:"
         Height          =   495
         Index           =   0
         Left            =   360
         TabIndex        =   1
         Top             =   720
         Width           =   735
      End
   End
End
Attribute VB_Name = "customer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Dim rsAll As New ADODB.Recordset

Dim bStatus As Integer
Public temp_userid As Long
Dim ClassificationArr(0 To 99) As Integer
Dim cSmallArr(0 To SUB_CLASS) As Integer
Dim cCollectArr(0 To 10) As Integer

Private Sub cmdAddClass_Click()
    frmAddClass.Show
    Me.Hide
End Sub

Private Sub cmdBlock_Click()
Dim sql As String
    Select Case bStatus
        Case 0:
            MsgBox "This user has not been activated!", vbOKOnly, SOFT_TITLE
        Case 1:
            bStatus = 9
            sql = "UPDATE `org_firststep` SET `acc_status`=9 WHERE temp_userid = " & temp_userid
            CloseRecordSet
            OperateDatabase rs, cn, sql
            cmdRefresh_Click
        Case 9:
            bStatus = 1
            sql = "UPDATE `org_firststep` SET `acc_status`=1 WHERE temp_userid = " & temp_userid
            CloseRecordSet
            OperateDatabase rs, cn, sql
            cmdRefresh_Click
        Case 10:
            bStatus = 10
            MsgBox "This user has been deleted!", vbOKOnly, SOFT_TITLE
        Case Default:
            MsgBox "Unknown status of this user!", vbOKOnly, SOFT_TITLE
    End Select
End Sub

Private Sub cmdDelete_Click()
    Dim sql As String
    If vbOK = MsgBox("Are you sure you want to delete it?", vbOKCancel, SOFT_TITLE) Then
        sql = "UPDATE `org_firststep` SET `acc_status`=10 WHERE temp_userid = '" & temp_userid & "'"
        CloseRecordSet
        OperateDatabase rs, cn, sql
        'cmdRefresh_Click
        lblUsrStatus.Caption = "Deleted"
        MsgBox "Deleted!", vbOKOnly, SOFT_TITLE
    End If
End Sub

Private Sub cmdLook_Click()
    Dim sURL As String
    Dim id As String
    
    If Trim(Text1(0).Text) = "" Then
        MsgBox "No customer!", vbOKOnly, SOFT_TITLE
        Exit Sub
    End If
    
    If Len(Text1(0).Text) < 9 Then
        id = Text1(0).Text
    Else
        id = Trim(str(val(Right(Text1(0).Text, 8))))
    End If
    sURL = "http://oversea.com.au/viewinfo-" & id & ".html"
    Load frmBrowser
    frmBrowser.cboAddress.Text = sURL
    frmBrowser.brwWebBrowser.Navigate sURL
    frmBrowser.Show
End Sub

Private Sub SearchAnID()
     Dim id, sql As String
'    On Error GoTo NoData
    If CustomerType = SEARCH_HISTORY Then
        id = temp_userid
    Else
        id = Trim(InputBox("Please enter the id or short id:", SOFT_TITLE, "22"))
    End If
    If id = "" Then
        Exit Sub
    End If
    
    If Len(id) < 9 Then
        sql = "select * from org_details where temp_userid=" & id & " limit 0, " & MAX_RET_ITEMS
    Else
        sql = "select * from org_details where usr_id=" & id & " limit 0, " & MAX_RET_ITEMS
    End If
    CloseRecordSet
    OperateDatabase rs, cn, sql
    If Not IsNull(rs) Then
        If rs.EOF Then
            MsgBox "Sorry! No data found!", vbOKOnly, SOFT_TITLE
        Else
            rs.MoveFirst
            Call LoadData2Field(rs)
        End If
    Else
        MsgBox "Sorry! No data found!", vbOKOnly, SOFT_TITLE
    End If
    
    cmdSettings.Enabled = False
    cmdNext.Enabled = False
NoData:
End Sub

Private Sub cmdLook4_Click()
    CustomerType = FIND_CUSTOMER
    SearchAnID
End Sub



Private Sub cmdNew_Click()
    Dim sql As String
    Dim max_id, input_id As Long
    disable_button_4_add
    sql = "select max(temp_userid) from org_firststep"
    CloseRecordSet
    OperateDatabase rs, cn, sql
    max_id = val(rs.Fields(0).value) + 1
    input_id = val(InputBox("ID of new customer will be: ", SOFT_TITLE, max_id))
    If input_id < max_id Then
        MsgBox "ID(" & input_id & ") can't be used, please input a new one larger than the recommanded one", vbOKOnly, SOFT_TITLE
        Exit Sub
    Else
        max_id = input_id
    End If
    
    Call ResetAllFields(max_id)
    If CustomerType <> NEW_CUS_YP Then
    'not sure why...
        'Text1(1).SetFocus
    End If
    temp_userid = max_id
    cmdUpdate.Enabled = True
    clrAllField
End Sub

Private Function ResetAllFields(ByVal id As Long)
    Text1(0).Text = id
End Function

Private Sub cmdNext_Click()
    Dim sql As String
    rsAll.MoveNext
    Call LoadData2Field(rsAll)
    
    sql = "INSERT INTO `rate`(type, date_time, city) VALUES ('1', '" & Format(Date$, "YYYY-MM-DD") & " " & Format(Time$, "HH:MM:SS") & "', " & CheckCity & ")"
    CloseRecordSet
    OperateDatabase rs, cn, sql
    Save2OpLog sql
End Sub

Private Sub cmdRefresh_Click()
    Dim sql As String
    On Error GoTo FreshData
    
    sql = "SET NAMES gbk"
    CloseRecordSet
    OperateDatabase rs, cn, sql
FreshData:
    sql = "select * from org_details where temp_userid =" & temp_userid
    CloseRecordSet
    OperateDatabase rs, cn, sql
    rs.MoveFirst
    Call LoadData2Field(rs)
    MsgBox "Refreshed!", vbOKOnly, SOFT_TITLE
End Sub

Private Sub cmdRight1_Click(Index As Integer)
        List1_DblClick Index
End Sub

Private Sub cmdSettings_Click()
    Unload Me
    frmCheckCustomers.Show
End Sub



Private Sub cmdUpdate_Click()
Dim sql As String
Dim bResult As Boolean
Dim edit_times As Integer
Dim thirdpart_upload, online_status, sort_id, city_id, recorder As Integer
Dim thrs As String
Dim i As Integer
Dim mainClass As Integer
Dim subClass As Integer

thirdpart_upload = Check1(0).value
recorder = Check1(1).value
sort_id = cmbClassification.ListIndex
city_id = cmbCity.ListIndex + 1
online_status = Check1(2).value
If ckHrs.value = 0 Then
    For i = 0 To 13
        If i = 13 Then
            thrs = thrs & Trim(tTime(i).Text)
        Else
            thrs = thrs & Trim(tTime(i).Text) & "|"
        End If
    Next i
Else
    thrs = Trim(txtTime.Text)
End If
'Check all data correct or not
Call CheckAllData(bResult)
If Not bResult Then
    Exit Sub
End If
Select Case CustomerType
'------------------------------------------------------------------------
Case CHECK_DATA, FIND_CUSTOMER, SEARCH_HISTORY:
If bResult Then
    If CustomerType = CHECK_DATA Then
        edit_times = val(rsAll.Fields(26).value) + 1
    End If
'Save to database
'UPDATE `org_details` SET `usr_id`=[value-1],`temp_userid`=[value-2],`curr_addr`=[value-3],`fax`=[value-4],
'`website`=[value-5],`thirdpart_upload`=[value-6],`birdate`=[value-7],`recorder`=[value-8],`slang`=[value-9],
'`self_intro`=[value-10],`usr_face`=[value-11],`usr_mails`=[value-12],`usr_phone`=[value-13],`usr_im`=[value-14],
'`online_status`=[value-15],`usr_shw_name`=[value-16],`rgist_time`=[value-17],`blacklist`=[value-18],
'`gd_friends_list`=[value-19],`event_id_list`=[value-20],`usr_level`=[value-21],`content_level`=[value-22],
'`sort_id`=[value-23],`city_id`=[value-24],`act_date`=[value-25],`hits`=[value-26] WHERE 1
sql = "UPDATE `org_details` SET `curr_addr`='" & AddSlashes(Trim(Text1(1).Text)) & "',`fax`='" & Trim(Text1(2).Text) & _
"',`website`='" & Trim(Text1(3).Text) & "',`thirdpart_upload` = " & thirdpart_upload & ", `recorder`= " & recorder & ", " & _
"`slang`='" & AddSlashes(Trim(Text1(6).Text)) & "',`self_intro`='" & AddSlashes(Trim(Text1(7).Text)) & "', `usr_face`='" & Text1(8).Text & _
"',`usr_mails`='" & Text1(9).Text & "', `usr_phone`='" & Trim(Text1(10).Text) & "', `usr_im`='" & Trim(Text1(11).Text) & _
"',`online_status` = " & online_status & ", `usr_shw_name` = '" & AddSlashes(Trim(Text1(13).Text)) & _
"', `blacklist`='" & Trim(Text1(15).Text) & "', `gd_friends_list` = '" & Trim(Text1(16).Text) & "', `event_id_list`= '" & _
Trim(Text1(17).Text) & "',`usr_level`=" & val(Trim(Text1(18).Text)) & ", `content_level`=" & val(Trim(Text1(19).Text)) & _
", `sort_id`=" & sort_id & ", `city_id`= " & city_id & ", `Edited` = " & edit_times & ", `TradingHrs`='" & thrs & "' WHERE `usr_id`=" & Trim(Text1(0).Text)
CloseRecordSet
OperateDatabase rs, cn, sql
If DB_IP = "localhost" Then
    Save2UpdateLog sql
End If

'update the org_firststep table
'UPDATE `org_firststep` SET `temp_userid`=[value-1],`org_name`=[value-2],`emailadd`=[value-3],`tel`=[value-4],
'`org_type`=[value-5],`user_pswd`=[value-6],`city_id`=[value-7],`curr_add`=[value-8],`act_pin`=[value-9],
'`acc_status`=[value-10],`date_time`=[value-11],`last_log_in`=[value-12] WHERE 1
sql = "UPDATE `org_firststep` SET `org_name`='" & AddSlashes(Trim(Text1(13).Text)) & "', `emailadd`='" & _
Trim(Text1(9).Text) & "', `tel`='" & Trim(Text1(10).Text) & "', `org_type`=1, `city_id`=" & city_id & ", `curr_add`= '" & _
AddSlashes(Trim(Text1(1).Text)) & "' WHERE `temp_userid`=" & temp_userid
CloseRecordSet
OperateDatabase rs, cn, sql
If DB_IP = "localhost" Then
    Save2UpdateLog sql
End If

'----update the sub classifications
i = 0
    'delete
    sql = "DELETE FROM `cs_classification` WHERE `temp_userid`=" & temp_userid
    CloseRecordSet
    OperateDatabase rs, cn, sql
If cCollectArr(0) <> 0 Then
    'insert
    While cCollectArr(i) <> 0
        subClass = cCollectArr(i)
        If Len(str(subClass)) = 5 Then
            mainClass = Left(subClass, 1)
        Else
            mainClass = Left(subClass, 2)
        End If
        sql = "INSERT INTO `cs_classification`(`temp_userid`, `FirstLevel`, `SecondLevel`) VALUES (" & _
        val(temp_userid) & ", " & mainClass & ", " & subClass & ")"
        CloseRecordSet
        OperateDatabase rs, cn, sql
        If DB_IP = "localhost" Then
            'save the update
            Save2UpdateLog sql
            'save the operation date and time
            sql = "INSERT INTO `rate`(type, date_time, city) VALUES ('0', '" & Format(Date$, "YYYY-MM-DD") & " " & Format(Time$, "HH:MM:SS") & "', " & CheckCity & ")"
            CloseRecordSet
            OperateDatabase rs, cn, sql
            Save2OpLog sql
        End If

        i = i + 1
    Wend
End If
MsgBox "Updated!", vbOKOnly, SOFT_TITLE
End If
'----------------------------------------------------------------------------
Case NEW_CUSTOMER, NEW_CUS_YP:
    Dim full_id As String
'formatn(details.temp_userId, 8, strlen(details.temp_userId));
    full_id = "1110000" & city_id & formatn(Trim(str(temp_userid)), 8)

'sprintf(details.userId, "1110000%d%s", baseInfo.city_id, details.temp_userId);
'INSERT INTO `org_details`(`usr_id`, `temp_userid`, `curr_addr`, `fax`, `website`,
'`thirdpart_upload`, `birdate`, `recorder`, `slang`, `self_intro`, `usr_face`, `usr_mails`, `usr_phone`,
'`usr_im`, `online_status`, `usr_shw_name`, `rgist_time`, `blacklist`, `gd_friends_list`, `event_id_list`,
'`usr_level`, `content_level`, `sort_id`, `city_id`, `act_date`, `hits`, `Edited`) '
'VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10],
'[value-11],[value-12],[value-13],[value-14],[value-15],[value-16],[value-17],[value-18],[value-19],[value-20],
'[value-21],[value-22],[value-23],[value-24],[value-25],[value-26],[value-27])
sql = "INSERT INTO `org_details`(`usr_id`, `temp_userid`, `curr_addr`, `fax`, `website`, `thirdpart_upload`, `recorder`, `slang`, `self_intro`, `usr_face`, `usr_mails`, `usr_phone`, `usr_im`, `online_status`,`usr_shw_name`, `blacklist`, `gd_friends_list`, `event_id_list`, `usr_level`, `content_level`, `sort_id`, `city_id`, `TradingHrs`) VALUES ('" & full_id & "'," & val(temp_userid) & ", '" & _
AddSlashes(Trim(Text1(1).Text)) & "', '" & Trim(Text1(2).Text) & "', '" & Trim(Text1(3).Text) & "', " & _
thirdpart_upload & ", " & recorder & ", '" & AddSlashes(Trim(Text1(6).Text)) & _
"', '" & AddSlashes(Trim(Text1(7).Text)) & "', '" & Text1(8).Text & "', '" & Text1(9).Text & "', '" & _
Trim(Text1(10).Text) & "', '" & Trim(Text1(11).Text) & "', " & online_status & ", '" & AddSlashes(Trim(Text1(13).Text)) & _
"', '" & Trim(Text1(15).Text) & "', '" & Trim(Text1(16).Text) & "', '" & _
Trim(Text1(17).Text) & "'," & val(Trim(Text1(18).Text)) & ", " & val(Trim(Text1(19).Text)) & ", " & sort_id & _
", " & city_id & ", '" & thrs & "')"
CloseRecordSet
OperateDatabase rs, cn, sql


'INSERT INTO `org_firststep`(`temp_userid`, `org_name`, `emailadd`, `tel`, `org_type`, `user_pswd`, `city_id`,
'`curr_add`, `act_pin`, `acc_status`, `date_time`, `last_log_in`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10],[value-11],[value-12])
sql = "INSERT INTO `org_firststep`(`temp_userid`, `org_name`, `emailadd`, `tel`, `org_type`, `user_pswd`, `city_id`, `curr_add`, `act_pin`, `acc_status`) VALUES (" & val(temp_userid) & _
", '" & AddSlashes(Trim(Text1(13).Text)) & "', '" & Trim(Text1(9).Text) & "', '" & Trim(Text1(10).Text) & "', 1, 'e10adc3949ba59abbe56e057f20f883e', " & _
city_id & ", '" & AddSlashes(Trim(Text1(1).Text)) & "', '0', 1 )"
CloseRecordSet
OperateDatabase rs, cn, sql
'-------Save the sub classifications to database ---------
i = 0
If cCollectArr(0) <> 0 Then
    While cCollectArr(i) <> 0
        subClass = cCollectArr(i)
        If Len(str(subClass)) = 5 Then
            mainClass = Left(subClass, 1)
        Else
            mainClass = Left(subClass, 2)
        End If
        sql = "INSERT INTO `cs_classification`(`temp_userid`, `FirstLevel`, `SecondLevel`) VALUES (" & _
        val(temp_userid) & ", " & mainClass & ", " & subClass & ")"
        CloseRecordSet
        OperateDatabase rs, cn, sql
        i = i + 1
    Wend
End If


MsgBox "New customer has been added to our system!", vbOKOnly, SOFT_TITLE
cmdUpdate.Enabled = False

End Select
End Sub



Private Sub Command1_Click()
    History.Show
End Sub

Private Sub Command2_Click()
    Dim currentId As String
    Dim sql As String
    
    If Text1(0).Text = "" Then
        MsgBox "Can not know the current ID", vbOKOnly, SOFT_TITLE
        Exit Sub
    End If
    If Len(Trim(Text1(0).Text)) > 8 Then
        currentId = val(Right(Trim(Text1(0).Text), 8))
    Else
        currentId = val(Trim(Text1(0).Text))
    End If
    sql = "select * from org_details where temp_userid < " & currentId & " order by temp_userid desc limit 0,1"
    CloseRecordSet
    OperateDatabase rs, cn, sql
    If Not rs.EOF Then
        rs.MoveFirst
        currentId = rs.Fields(0).value
        temp_userid = str(Right(Trim(currentId), 8))
        CustomerType = SEARCH_HISTORY
        Call SearchFunction(rs)
    Else
        MsgBox "It reaches the beginning!", vbOKOnly, SOFT_TITLE
    End If
End Sub

Private Sub Command3_Click()
     Dim currentId As String
     Dim sql As String
    
    If Text1(0).Text = "" Then
        MsgBox "Can not know the current ID", vbOKOnly, SOFT_TITLE
        Exit Sub
    End If
    If Len(Trim(Text1(0).Text)) > 8 Then
        currentId = val(Right(Trim(Text1(0).Text), 8))
    Else
        currentId = val(Trim(Text1(0).Text))
    End If
    sql = "select * from org_details where temp_userid > " & currentId & " order by temp_userid asc limit 0, 1"
    CloseRecordSet
    OperateDatabase rs, cn, sql
    If Not rs.EOF Then
        rs.MoveFirst
        currentId = rs.Fields(0).value
        temp_userid = str(Right(Trim(currentId), 8))
        CustomerType = SEARCH_HISTORY
        Call SearchFunction(rs)
    Else
        MsgBox "It reaches the last record!", vbOKOnly, SOFT_TITLE
    End If
End Sub



Private Sub Form_Load()
    Select Case CustomerType
        Case INIT_STATUS:
            MsgBox "Unkown option!", vbOKOnly, SOFT_TITLE
            Exit Sub
        Case CHECK_DATA:
            frmSplash.Show
            DoEvents
            cmdSettings.Visible = True
            cmdNext.Visible = True
            cmdRefresh.Visible = True
            Call LoadValidItem
            DoEvents
            Unload frmSplash
        Case FIND_CUSTOMER, SEARCH_HISTORY:
            frmSplash.Show
            DoEvents
            cmdSettings.Visible = False
            cmdNext.Visible = False
            cmdRefresh.Visible = False
            cmdNew.Visible = False
            Call Cn2Oversea(cn)
            InitClassificationList
            CloseRecordSet
            DoEvents
            InitCityList
            SearchAnID
            DoEvents
            Unload frmSplash
        Case NEW_CUSTOMER, NEW_CUS_YP:
            Check1(0).value = 1
            Check1(1).value = 1
            init_tTime
            disable_button_4_add
            Call Cn2Oversea(cn)
            InitClassificationList
            CloseRecordSet
            InitCityList
            cmdNew_Click
    End Select
End Sub

Private Sub SearchFunction(ByVal rs As ADODB.Recordset)
    clrAllField
    cmdSettings.Visible = False
    cmdNext.Visible = False
    cmdRefresh.Visible = False
    cmdNew.Visible = False
    'InitClassificationList
    'CloseRecordSet
    'InitCityList
    'cmdLook4_Click
    LoadData2Field rs
End Sub

Private Sub init_tTime()
    Dim i As Integer
    For i = 0 To 13
        If i Mod 2 = 0 Then
            tTime(i).Text = "9:00 am"
        Else
            tTime(i).Text = "5:00 pm"
        End If
    Next i
End Sub

Private Sub disable_button_4_add()
    cmdSettings.Visible = False
    cmdNext.Visible = False
    cmdLook4.Visible = False
    cmdDelete.Visible = False
    cmdRefresh.Visible = False
    cmdBlock.Visible = False
    
    cmdUpdate.Enabled = False
End Sub

Public Function LoadValidItem()
    Dim sql As String
    Dim CatalogCondition As String
    Call Cn2Oversea(cn)
    InitClassificationList
    CloseRecordSet
    InitCityList
    CloseRecordSet
    'list all records according to hits
    If CheckCatalog <> 99 Then
       ' CatalogCondition = " and checkcataglog"
    Else
        'CatalogCondition = ""
    End If
    sql = "select * from org_details where city_id=" & CheckCity & " and Checked=0 order by Edited ASC, hits desc limit 0, " & MAX_RET_ITEMS
    OperateDatabase rsAll, cn, sql
    rsAll.MoveFirst
    
    
    Call LoadData2Field(rsAll)
End Function

Private Sub clrAllField()

    Text1(1).Text = ""
    Text1(2).Text = ""
    Text1(3).Text = ""
    
    Text1(6).Text = ""
    Text1(7).Text = ""
    Text1(8).Text = ""
    Text1(9).Text = ""
    
    Text1(10).Text = ""
    Text1(11).Text = ""
    Text1(13).Text = ""
    Text1(14).Text = ""
    
    Text1(15).Text = ""
    Text1(16).Text = ""
    Text1(17).Text = ""
    Text1(18).Text = ""
    Text1(19).Text = ""
    
    Text1(22).Text = ""
    If CustomerType <> NEW_CUSTOMER And CustomerType <> NEW_CUS_YP Then
        Check1(0).value = 0
        Check1(1).value = 0
    End If
    Check1(2).value = 0
End Sub

Public Function LoadData2Field(rsAll As ADODB.Recordset)
    Dim sql As String
    
    Dim city As String
    Dim classification As String
    Dim i As Integer
    Dim TradingHrs As String
    
    ClrClassificationArr
    ClrCollectionArr
    List1(1).Clear
    List1(2).Clear
    
    Text1(0).Text = rsAll.Fields(0).value
    
    temp_userid = val(rsAll.Fields(1).value)
    
    Text1(1).Text = rsAll.Fields(2).value
    Text1(2).Text = rsAll.Fields(3).value
    Text1(3).Text = rsAll.Fields(4).value
    
    Check1(0).value = rsAll.Fields(5).value
    
    Text1(4).Text = rsAll.Fields(6).value
    
    Check1(1).value = rsAll.Fields(7).value
    
    Text1(6).Text = rsAll.Fields(8).value
    
    Text1(7).Text = rsAll.Fields(9).value
    Text1(8).Text = rsAll.Fields(10).value
    Text1(9).Text = rsAll.Fields(11).value
    Text1(10).Text = rsAll.Fields(12).value
    
    Text1(11).Text = rsAll.Fields(13).value
    
    
    Check1(2).value = rsAll.Fields(14).value 'thirdpart upload
    
    
    Text1(13).Text = rsAll.Fields(15).value 'trading name

    Text1(14).Text = rsAll.Fields(16).value 'birthday
    
    
    Text1(15).Text = rsAll.Fields(17).value
    
    Text1(16).Text = rsAll.Fields(18).value
    
    Text1(17).Text = rsAll.Fields(19).value
    
    Text1(18).Text = rsAll.Fields(20).value
    
    Text1(19).Text = rsAll.Fields(21).value
    
    city = rsAll.Fields(23).value
    classification = rsAll.Fields(22).value
    Text1(22).Text = rsAll.Fields(24).value
    
    TradingHrs = rsAll.Fields(27).value
    Call UpdateTradingHrsFields(TradingHrs)
    
    Frame1.Caption = "Basic Information - Hits: " & rsAll.Fields(25).value & " Edited Times: " & rsAll.Fields(26).value
    sql = "select * from cs_city_list where city_id <100"
    CloseRecordSet
    i = 0
    OperateDatabase rs, cn, sql
    If Not IsNull(rs) Then
        rs.MoveFirst
        While Not rs.EOF
            If rs.Fields(0).value = city Then
                cmbCity.ListIndex = i
                GoTo NextStep1
            End If
            rs.MoveNext
            i = i + 1
        Wend
    End If
NextStep1:
    sql = "select Sort_ID from cs_sort where Sort_ID < 100 order by Sort_ID ASC"
    CloseRecordSet
    i = 0
    OperateDatabase rs, cn, sql
    If Not IsNull(rs) Then
        rs.MoveFirst
        While Not rs.EOF
            If rs.Fields(0).value = classification Then
                cmbClassification.ListIndex = i
                GoTo NextStep
            End If
            rs.MoveNext
            i = i + 1
        Wend
    End If
    
NextStep:
    sql = "select acc_status, temp_userid from org_firststep where temp_userid = " & temp_userid
    CloseRecordSet
    OperateDatabase rs, cn, sql
    If Not IsNull(rs) Then
        rs.MoveFirst
        bStatus = Trim(rs.Fields(0).value)
        Select Case Trim(rs.Fields(0).value)
        Case 0:
        'picStatus.Picture = LoadPicture("./Image/NA.GIF")
        lblUsrStatus.Caption = "Normal"
        Case 1:
        'picStatus.Picture = LoadPicture("./Image/Running.GIF")
        lblUsrStatus.Caption = "Running"
        cmdBlock.Caption = "Block"
        Case 9:
        'picStatus.Picture = LoadPicture("./Image/blocked.GIF")
        lblUsrStatus.Caption = "Blocked"
        cmdBlock.Caption = "Active"
        Case 10:
        cmdBlock.Caption = "Block"
        cmdBlock.Enabled = False
        'picStatus.Picture = LoadPicture("./Image/deleted.gif")
        lblUsrStatus.Caption = "Deleted"
        Case Default:
        'picStatus.Picture = LoadPicture("./Image/Running.GIF")
        lblUsrStatus.Caption = "Running"
        End Select
    End If
    
    Call LoadAllClassification(temp_userid)
    'update the checked flag
    UpdateCheckFlag temp_userid
End Function

Private Sub UpdateCheckFlag(ByVal id As Long)
    Dim sql As String
    Dim rsUpdate As New ADODB.Recordset
    If CustomerType = CHECK_DATA Then
        sql = "update org_details set Checked=1 where temp_userid=" & id
        OperateDatabase rsUpdate, cn, sql
    End If
End Sub

Private Function LoadAllClassification(ByVal temp_userid As Long)
    Dim sql As String
    Dim i As Integer
    List1(2).Clear
    sql = "SELECT `Sort_Name`,`Sort_ID` FROM `cs_sort` where `Sort_ID` in (select `SecondLevel` from `cs_classification` WHERE `temp_userid`=" & temp_userid & ")"
    CloseRecordSet
    OperateDatabase rs, cn, sql
    i = 0
    While Not rs.EOF
        List1(2).AddItem rs.Fields(0).value
        cCollectArr(i) = val(rs.Fields(1).value)
        i = i + 1
        rs.MoveNext
    Wend
End Function

Private Sub Form_Unload(Cancel As Integer)
    On Error GoTo CloseConnection
    CloseRecordSet
    If Not IsNull(rsAll) Then
        rsAll.Close
    End If
CloseConnection:
    cn.Close
End Sub


Public Sub InitCityList()
    Dim sql As String
    'cmbCity.AddItem "Unknown"
    sql = "select * from cs_city_list"
    CloseRecordSet
    OperateDatabase rs, cn, sql
    If Not IsNull(rs) Then
        rs.MoveFirst
        While Not rs.EOF
        cmbCity.AddItem rs.Fields(1).value & "-" & rs.Fields(2).value
        rs.MoveNext
        Wend
    End If
End Sub


Public Sub InitClassificationList()
    Dim sql As String
    Dim i As Integer
    i = 0
    'cmbClassification.AddItem "Unknown"
    sql = "select Sort_ID, Sort_Name from cs_sort where bMain=1"
    CloseRecordSet
    OperateDatabase rs, cn, sql
    If Not IsNull(rs) Then
        rs.MoveFirst
        While Not rs.EOF
        cmbClassification.AddItem rs.Fields(1).value
        List1(0).AddItem rs.Fields(1).value
        ClassificationArr(i) = rs.Fields(0).value
        i = i + 1
        rs.MoveNext
        Wend
    End If
    
    List1(1).Clear
    ClrClassificationArr
    List1(2).Clear
    ClrCollection
End Sub

Private Sub ClrClassificationArr()
    Dim i As Integer
    For i = 0 To SUB_CLASS
        cSmallArr(i) = 0
    Next i
End Sub

Private Sub ClrCollectionArr()
    Dim i As Integer
    For i = 0 To 10
        cCollectArr(i) = 0
    Next i
End Sub


Private Sub ClrCollection()
    Dim i As Integer
    For i = 0 To 10
        cCollectArr(i) = 0
    Next i
End Sub

Private Function CheckAllData(ByRef bResult As Boolean)
bResult = True
'address
If (Trim(Text1(1).Text) = "") Then
    bResult = False
    MsgBox "Address can't be empty!", vbOKOnly, SOFT_TITLE
    Text1(1).SetFocus
    
    Exit Function
End If
If (Trim(Text1(13).Text) = "") Then
    bResult = False
    MsgBox "Business name can't be empty!", vbOKOnly, SOFT_TITLE
    Text1(13).SetFocus
    Exit Function
End If

If cmbClassification.ListIndex = -1 Then
    bResult = False
    MsgBox "Classification is not specified!", vbOKOnly, SOFT_TITLE
    cmbClassification.SetFocus
    Exit Function
End If

If cmbCity.ListIndex = -1 Then
    bResult = False
    MsgBox "City is not specified!", vbOKOnly, SOFT_TITLE
    cmbCity.SetFocus
    Exit Function
End If
End Function


Public Function UpdateTradingHrsFields(ByVal TradingHrs As String)
    Dim i, iIndex, length As Integer
    Dim str, char As String
    init_tTime
    length = Len(TradingHrs)
    If length = 0 Then
        Exit Function
    End If
    'see which sort of time
    i = InStr(TradingHrs, "|")
    If i = 0 Then
        txtTime.Text = TradingHrs
        ckHrs.value = 1
    Else
        ckHrs.value = 0
        iIndex = 0
        str = ""
        For i = 1 To length
            char = Mid(TradingHrs, i, 1)
            If char = "|" Then
                tTime(iIndex).Text = str
                iIndex = iIndex + 1
                str = ""
            Else
                str = str & char
            End If
        Next i
        tTime(iIndex).Text = str
    End If
End Function

Private Sub CloseRecordSet()
On Error GoTo NoErr
        rs.Close
NoErr:
End Sub

Private Sub List1_DblClick(Index As Integer)
    Dim id As Integer
    Dim sql As String
    Dim i, j As Integer
    i = 0
    j = 0
    Select Case Index
        'parent classification
        Case 0:
        If List1(0).ListIndex = -1 Then
            MsgBox "Please choose one item!", vbOKOnly, SOFT_TITLE
            Exit Sub
        Else
            id = ClassificationArr(List1(0).ListIndex)
            'sql = "select `Sort_ID` from `cs_sort` where bMain=0 and Sort_ID like '" & str(id) & "___'"
            sql = "SELECT `Sort_ID`, `Sort_Name` FROM  `cs_sort` Where bMain = 0 AND Sort_ID LIKE  '" & Trim(str(id)) & "___' "
            CloseRecordSet
            OperateDatabase rs, cn, sql
            List1(1).Clear
            ClrClassificationArr
            While Not rs.EOF
                List1(1).AddItem rs.Fields(1).value
                cSmallArr(i) = rs.Fields(0).value
                i = i + 1
                If i > SUB_CLASS Then
                    MsgBox "Oooo, buddy, do you think it's too many?", vbOKOnly, SOFT_TITLE
                    Exit Sub
                End If
                rs.MoveNext
            Wend
        End If
        'child classification
        Case 1:
            If List1(1).ListIndex = -1 Then
                MsgBox "Please choose one item!", vbOKOnly, SOFT_TITLE
                Exit Sub
            Else
                id = cSmallArr(List1(1).ListIndex)
                'check see if it was saved
                If IsSavedID(id) Then
                    MsgBox "Buddy, you have picked up this!", vbOKOnly, SOFT_TITLE
                    Exit Sub
                Else
                    If SaveOneId(id) Then
                        List1(2).AddItem List1(1).Text
                    Else
                        MsgBox "Buddy, you can't picked up so many!", vbOKOnly, SOFT_TITLE
                        Exit Sub
                    End If
                End If
            End If
        Case 2:
        'delete one record
            If List1(2).ListIndex = -1 Then
                MsgBox "Please choose one item!", vbOKOnly, SOFT_TITLE
                Exit Sub
            Else
                id = cCollectArr(List1(2).ListIndex)
                If vbOK = MsgBox("Delete? Are you sure?", vbOKCancel, SOFT_TITLE) Then
                    Call GetRidOfThisItem(List1(2).ListIndex)
                    List1(2).RemoveItem (List1(2).ListIndex)
                End If
            End If
    End Select
End Sub


Private Function GetRidOfThisItem(ByVal iIndex As Integer)
    Dim i As Integer
    For i = iIndex To 9
        cCollectArr(i) = cCollectArr(i + 1)
    Next i
    cCollectArr(10) = 0
End Function

Private Function SaveOneId(ByVal id As Integer) As Boolean
    Dim i As Integer
    For i = 0 To 10
        If cCollectArr(i) = 0 Then
            cCollectArr(i) = id
            SaveOneId = True
            Exit Function
        End If
    Next i
    
    SaveOneId = False
End Function


Private Function IsSavedID(ByVal id As Integer) As Boolean
    Dim bSaved As Boolean
    Dim i As Integer
    bSaved = False
    i = 0
    For i = 0 To 10
        If cCollectArr(i) = id Then
            bSaved = True
            Exit For
        End If
    Next i
    
    IsSavedID = bSaved
End Function
